package br.edu.ufcg.dsc;

import br.edu.ufcg.dsc.domain.PersistenceBaseClass;
import br.edu.ufcg.dsc.domain.UserType;

public class Main extends PersistenceBaseClass {

	public static void main(String[] args) throws Exception {

		Main m = new Main();
		m.setUp();
		/*List<Integer> id =  m.entityMgr
		.createNativeQuery(
				"select r.id "
						+ "from resource r, datafield d, datafield_subfields ds, "
						+ "marc_resource mr, marc_resource_datafield mrd "
						+ "where r.type = :type and r.marc_id = mr.id and mrd.marc_resource_id = mr.id and "
						+ "mrd.datafields_id = d.id and mrd.mapkey = :field and "
						+ "ds.datafield_id = d.id and ds.mapkey like :subfield and "
						+ "ds.element like :value").setParameter("type",
				0).setParameter("field", "245").setParameter(
				"subfield", "a" + "%").setParameter("value", "Arithmetic"+ "%")
		.getResultList();

		for (int s : id) {
			Resource r = m.entityMgr.find(Resource.class, s);
			System.out.println(new MARCXMLGenerator().generate(r.getMarc()));
			System.exit(0);
		}*/

/*		List<String> co =  m.entityMgr.createNativeQuery("select m.m from mb m").getResultList();
		
		for (int i=10; i< co.size(); i++) {
			MARCResource marc = new MARCXMLParser().parseResource(co.get(i));
			Resource r = new Resource(marc, ResourceType.BOOK);
			ResourceService.persist(r);
		}*/
		//List<String> titulos =  m.entityMgr.createNativeQuery("select e.titulo from  m").getResultList();
		
		//List<Resource> r = ResourceService.findByAuthor("Sandburg", ResourceType.BOOK);
		
	//	System.out.println(r.size());
		
		
//		List<Resource> list = m.entityMgr.createQuery("select r from br.edu.ufcg.dsc.domain.Resource r where r.marc.dataFields[:field] is not null").setParameter("field", "245").getResultList();

		// Object o =
		// m.entityMgr.createQuery("select u from br.edu.ufcg.dsc.domain.Unit u where u.getResource().getMarc().getDataFields().get(:field) is not null").setParameter("field",
		// "245").getSingleResult();
		//Unit u = m.entityMgr.find(Unit.class, "2010.00002");

//		System.out.println(new MARCXMLGenerator().generate(list.get(0).getMarc()));

	m.tearDown();
	}

}
